﻿using System.Linq;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Async;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ArcGIS.Client.Tasks.Async.Tests
{
    [TestClass]
    public class ArcGISDynamicMapServiceLayerTests : SilverlightTest
    {
        private ArcGISDynamicMapServiceLayer _layer;

        [TestInitialize]
        public void Initialize()
        {
            _layer = new ArcGISDynamicMapServiceLayer
            {
                Url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"
            };
        }

        [TestMethod, Asynchronous]
        public async void GetAllDetails()
        {

            var details = await _layer.GetAllDetailsTaskAsync();
            Assert.IsTrue(details.Any());
            TestComplete();
        }

        [TestMethod, Asynchronous, Description("Layer must be initialized before querying a legend")]
        public async void QueryLegendInfos()
        {
            await _layer.InitializeTaskAsync();
            var legendInfos = await _layer.QueryLegendInfosTaskAsync();
            Assert.IsNotNull(legendInfos);
            TestComplete();
        }
    }
}
